/**
 * Created by hcadmin on 16/6/14.
 */
var Action = require("../apiaction");
var DataProxy = require("data-proxy");
var httpconf=require('../../node_modules/data-proxy/lib/httpconf.js');
var Utility = require("../Utility/utility.js");

exports.userRouter = function(router){

    //用户管理-用户列表
    router.all('/userlist',function(req,res){

        //获取用户总数
        var pamar={};
        pamar["method"]='GET';
        Action.send(req,res,'/users/count',pamar,function(res,data){

            var json=JSON.parse(data);

            console.log(json);

            res.render('96053/01Usermanage/userlist', {
                layout: '96053/layout-96053',
                active: 'userlist',
                jscript: '96053/01Usermanage/userlist',
                data:json
            })
        })

    });

    //用户管理-孕期体检
    router.all('/96053/gestation',function(req,res){

        res.render('96053/01Usermanage/gestation', {
            layout: '96053/layout-96053',
            active: 'gestation',
            jscript: '96053/01Usermanage/gestation'
        })
    });


    //医生管理-审核管理
    router.all('/96053/examine',function(req,res){
        var param={method:"GET"};
        Action.send(req, res, 'area', param, function (res, data) {
            var json = JSON.parse(data);
            res.render('96053/02Doctormanage/examine', {
                layout: '96053/layout-96053',
                active: 'examine',
                jscript: '96053/02Doctormanage/examine',
                provincelist:json.data.provinceList
            })
        });
    });

    //医生管理-普通医生
    router.all('/96053/ordinary',function(req,res){
        var param={method:"GET"};
        Action.send(req, res, 'area', param, function (res, data) {
            var json = JSON.parse(data);
            res.render('96053/02Doctormanage/ordinary', {
                layout: '96053/layout-96053',
                active: 'ordinary',
                jscript: '96053/02Doctormanage/ordinary',
                provincelist:json.data.provinceList
            })
        });
    });

    //医生管理-名医管理
    router.all('/96053/famousdoctor',function(req,res){
        var param={method:"GET"};
        Action.send(req, res, 'area', param, function (res, data) {
            var json = JSON.parse(data);
            res.render('96053/02Doctormanage/famousdoctor', {
                layout: '96053/layout-96053',
                active: 'famousdoctor',
                jscript: '96053/02Doctormanage/famousdoctor',
                provincelist:json.data.provinceList,
            })

        });

    });

    //医生管理-省市级医生
    router.all('/96053/provincialcity',function(req,res){
        var param={method:"GET"};
        Action.send(req, res, 'area', param, function (res, data) {
            var json = JSON.parse(data);
            res.render('96053/02Doctormanage/provincialcity', {
                layout: '96053/layout-96053',
                active: 'provincialcity',
                jscript: '96053/02Doctormanage/provincialcity',
                provincelist:json.data.provinceList
            })
        });
    });

    //医生管理-热榜医生榜
    router.all('/96053/hotlist',function(req,res){
        res.render('96053/02Doctormanage/hotlist', {
            layout: '96053/layout-96053',
            active: 'hotlist',
            jscript: '96053/02Doctormanage/hotlist'
        })
    });

    //医生管理-热榜医生人工调整
    router.all('/96053/adjust',function(req,res){

        res.render('96053/02Doctormanage/adjustmentLabor', {
            layout: '96053/layout-96053',
            active: 'hotlist',
            jscript: '96053/02Doctormanage/adjustmentLabor'
        })
    });

    //医院管理
    router.all('/96053/hospital',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows};
        param["method"]="GET";
        Action.send(req, res, '/new/area', param, function (res, data) {
            Action.send(req,res,'/new/hospital_levels/list',param,function(res,data2){
                var json = JSON.parse(data);
                var json2 = JSON.parse(data2)
                res.render('96053/03Hospitalmanage/hospital', {
                    layout: '96053/layout-96053',
                    active: '',
                    jscript: '96053/03Hospitalmanage/hospital',
                    provincelist:json.data.provinceList,
                    hosptiallevel:json2.data
                })
            })

        })

    });

    //咨询订单管理
    router.all('/96053/consultingorder',function(req,res){

        res.render('96053/04ConsultingOrderManage/consultingorder', {
            layout: '96053/layout-96053',
            active: 'consultingorder',
            jscript: '96053/04ConsultingOrderManage/consultingorder'
        })
    });

    //图文管理-栏目管理
    router.all('/96053/column',function(req,res){

        var param={};
        param['method']='GET';
        param['page']=1;

        //列表
        Action.send(req, res, 'artcate/list', param, function (res, data) {

            var json = JSON.parse(data);

            var article=json.data.rows;

            res.render('96053/05PictureTextmanage/column', {
                layout: '96053/layout-96053',
                active: 'column',
                jscript: '96053/05PictureTextmanage/column',
                article:article
            })
        })


    });
    //图文管理-文章管理
    router.all('/96053/article',function(req,res){

        var param={};
        param['method']='GET';
        param['page']=1;
        //列表
        Action.send(req, res, 'artcate/list', param, function (res, data) {

            var json = JSON.parse(data);

            var artcate=json.data.rows;

            //console.log(artcate);

            res.render('96053/05PictureTextmanage/article', {
                layout: '96053/layout-96053',
                active: 'article',
                jscript: '96053/05PictureTextmanage/article',
                artcate:artcate
            })
        });
    });

    //管理员管理
    router.all('/96053/manager',function(req,res){

        var parmas={};
        parmas.method='GET';
        //取得系统所有权限
        Action.send(req,res,'roles/list',parmas,function(res,data){

            var json=JSON.parse(data);
            var roles=json.data;
            //console.log(roles);

            res.render('96053/06Managermanage/manager', {
                layout: '96053/layout-96053',
                active: '',
                jscript: '96053/06Managermanage/manager',
                roles:data
            })

        });
    });

    //资金管理
    router.all('/96053/fundmanage',function(req,res){
        var params={};
        params.method='GET';
        Action.send(req,res,'admin/platdata',params,function(res,data) {
            var json=JSON.parse(data);
            res.render('96053/07Fundmanage/fundmanage', {
                layout: '96053/layout-96053',
                active: '',
                jscript: '96053/07Fundmanage/fundmanage',
                inconme:json.data
            })
        })
    });
    //工资结算系统
    router.all('/96053/salaryaccounting',function(req,res){
        var url = "http://"+ httpconf.host+":"+httpconf.port+httpconf.root+"settlementLog/export"
        res.render('96053/07Fundmanage/salaryaccounting', {
            layout: '96053/layout-96053',
            active: '',
            jscript: '96053/07Fundmanage/salaryaccounting',
            url:url
        })
    });
    //已结算账单
    router.all('/96053/bill',function(req,res){
        var url = "http://"+ httpconf.host+":"+httpconf.port+httpconf.root+"settlementLog/export/finish";
        res.render('96053/07Fundmanage/bill', {
            layout: '96053/layout-96053',
            active: '',
            jscript: '96053/07Fundmanage/bill',
            url:url
        })
    });

//----------------------------------96053 二期----------------------------------------//
    //直播管理
    router.all('/96053/directseeding',function(req,res){
        var selectTime= req.param('selectTime');
        var params = {
            doctor_type_id:3,
            method:"GET"
        };
        Action.send(req,res,'doctorslist',params,function(res,data){
            var json=JSON.parse(data);
            var param2={method:"GET"};
            Action.send(req, res, 'area', param2, function (res, data2) {
                var json2=JSON.parse(data2);
                res.render('96053/08directseeding/directseeding', {
                    layout: '96053/layout-96053',
                    active: 'directseeding',
                    jscript: '96053/08directseeding/directseeding',
                    data:json.data,
                    selectTime:selectTime,
                    provincelist:json2.data.provinceList
                })});
        })
    });

    //家政管理--家政公司管理
    router.all('/96053/homemakecompany',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows};
        param["method"]="GET";
        Action.send(req, res, 'area', param, function (res, data) {
            var json = JSON.parse(data);
            res.render('96053/09homemaking/homemakecompany', {
                layout: '96053/layout-96053',
                active: 'homemakecompany',
                jscript: '96053/09homemaking/homemakecompany',
                provincelist:json.data.provinceList
            })
        });
    });

    //家政管理--家政公司管理-家政公司详情
    router.all('/96053/company_detail',function(req,res){
        var company_id = req.param('company_id');
        //console.log(company_id)
        var param={};
        param["method"]="GET";
        Action.send(req, res, 'area', param, function (res, data) {
            var json = JSON.parse(data);
            var param2={};
            param2["method"]="GET";
            Action.send(req, res, '/new/homemaking_company/'+company_id, param2, function (res, data) {
                var json2 = JSON.parse(data);
                console.log(json2);
                res.render('96053/09homemaking/company_detail', {
                    layout: '96053/layout-96053',
                    active: 'homemakecompany',
                    jscript: '96053/09homemaking/company_detail',
                    provincelist: json.data.provinceList,
                    company_detail:json2.data
                })
            });

        });
    });

    //家政管理--服务管理
    router.all('/96053/homemakeservice',function(req,res){

        res.render('96053/09homemaking/homemakeservice', {
            layout: '96053/layout-96053',
            active: 'homemakeservice',
            jscript: '96053/09homemaking/homemakeservice'

        })
    });

    //卡券管理
    router.all('/96053/card',function(req,res){

        res.render('96053/10card/card', {
            layout: '96053/layout-96053',
            active: 'card',
            jscript: '96053/10card/card'

        })

    });

    //名医直播
    router.all('/96053/famousdoctorsLive',function(req,res){
        var selectTime= req.param('selectTime');
        var doctor_id = req.param("doctor_id");
        res.render('96053/02Doctormanage/famousdoctorsLive', {
            layout: '96053/layout-96053',
            active: 'famousdoctor',
            jscript: '96053/02Doctormanage/famousdoctorsLive',
            doctor_id:doctor_id,
            selectTime:selectTime
        })
    });
    //家政订单管理
    router.all('/96053/homemakeorder',function(req,res){

        var params={};
        params.method="GET";
        Action.send(req,res,'/new/homemaking_company/all',params,function(res,data) {

            var json2 = JSON.parse(data);

            res.render('96053/04ConsultingOrderManage/homemakeorder', {
                layout: '96053/layout-96053',
                active: 'homemakeorder',
                jscript: '96053/04ConsultingOrderManage/homemakeorder',
                company:json2.data
            })
        });
    });
    //家政订单管理-未接单
    router.all('/96053/order_no_single',function(req,res){
        var baby_sister_appointment_id = req.param('baby_sister_appointment_id');
        var params={
            baby_sister_appointment_id:baby_sister_appointment_id,
            method:'GET'
        };
        Action.send(req,res,'/new/baby_sister_appointment/'+baby_sister_appointment_id,params,function(res,data) {

            var json = JSON.parse(data);

            console.log(json);
            res.render('96053/04ConsultingOrderManage/order_no_single', {
                layout: '96053/layout-96053',
                active: 'homemakeorder',
                jscript: '96053/04ConsultingOrderManage/order_no_single',
                data:json.data
            })
        });
    });
    //家政订单管理-已接单
    router.all('/96053/order_yes_single',function(req,res){

        var baby_sister_appointment_id = req.param('baby_sister_appointment_id');
        var params={
            baby_sister_appointment_id:baby_sister_appointment_id,
            method:'GET'
        };
        Action.send(req,res,'/new/baby_sister_appointment/'+baby_sister_appointment_id,params,function(res,data) {

            var json = JSON.parse(data);

            //console.log(json);

            res.render('96053/04ConsultingOrderManage/order_yes_single', {
                layout: '96053/layout-96053',
                active: 'homemakeorder',
                jscript: '96053/04ConsultingOrderManage/order_yes_single',
                data:json.data
            })
        });
    });
    //家政订单管理-已接单-服务费用清单
    router.all('/96053/cost_detailed',function(req,res){

        var baby_sister_appointment_id = req.param('baby_sister_appointment_id');
        var params={
            baby_sister_appointment_id:baby_sister_appointment_id,
            method:'GET'
        };
        Action.send(req,res,'/new/baby_sister_server/list',params,function(res,data) {
            var json = JSON.parse(data);
            console.log(json);
            res.render('96053/04ConsultingOrderManage/cost_detailed', {
                layout: '96053/layout-96053',
                active: 'homemakeorder',
                jscript: '96053/04ConsultingOrderManage/cost_detailed',
                baby_sister_appointment_id:baby_sister_appointment_id,
                data:json
            })
        });
    });
    //根据公司-服务人员列表
    router.all('/96053/service_people',function(req,res){

        var page = req.param('page');
        var rows = req.param('rows');
        var company_id=req.param('company_id');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows};
        param["method"]="GET";
        Action.send(req, res, 'area', param, function (res, data) {
            var json = JSON.parse(data);

            var params = {
                method:'GET',
                page:page,
                rows:rows
            };
            Action.send(req, res, '/new/homemaking_company/list', params, function (res, data2) {

                var json2=JSON.parse(data2);
                //console.log(json2);

                res.render('96053/09homemaking/service_people', {
                    layout: '96053/layout-96053',
                    active: 'homemakecompany',
                    jscript: '96053/09homemaking/service_people',
                    provincelist: json.data.provinceList,
                    company_id: company_id,
                    company:json2.data.rows
                })
            })
        });
    });

    //服务类别管理-月嫂
    router.all('/96053/service_people_list',function(req,res){

        var page = req.param('page');
        var rows = req.param('rows');
        var company_id=req.param('company_id');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows};
        param["method"]="GET";
        Action.send(req, res, 'area', param, function (res, data) {
            var json = JSON.parse(data);

            var params = {
                method:'GET',
                page:page,
                rows:rows
            };
            Action.send(req, res, '/new/homemaking_company/list', params, function (res, data2) {

                var json2=JSON.parse(data2);
                //console.log(json2);

                res.render('96053/09homemaking/service_people_list', {
                    layout: '96053/layout-96053',
                    active: 'homemakeservice',
                    jscript: '96053/09homemaking/service_people_list',
                    provincelist: json.data.provinceList,
                    company_id: company_id,
                    company:json2.data.rows
                })
            })
        });
    });

};


